package com.tanhua.sso.utils;
import com.aliyun.dysmsapi20170525.models.SendSmsRequest;
import com.aliyuncs.CommonRequest;
import com.aliyuncs.CommonResponse;
import com.aliyuncs.DefaultAcsClient;
import com.aliyuncs.IAcsClient;
import com.aliyuncs.http.MethodType;
import com.aliyuncs.profile.DefaultProfile;
import org.apache.commons.lang3.RandomUtils;
import org.apache.commons.lang3.StringUtils;
import com.aliyun.tea.*;
import com.aliyun.dysmsapi20170525.*;
import com.aliyun.dysmsapi20170525.models.*;
import com.aliyun.teaopenapi.*;
import com.aliyun.teaopenapi.models.*;
import java.io.InputStream;
import java.util.Properties;
public class sendmsgutils {
    public static com.aliyun.dysmsapi20170525.Client createClient(String accessKeyId, String accessKeySecret) throws Exception {
        Config config = new Config()
                // 您的AccessKey ID
                .setAccessKeyId(accessKeyId)
                // 您的AccessKey Secret
                .setAccessKeySecret(accessKeySecret);
        // 访问的域名
        config.endpoint = "dysmsapi.aliyuncs.com";
        return new com.aliyun.dysmsapi20170525.Client(config);
    }

    public static String sendMsg(String phone,String templateCode ,String code) throws Exception {
        /*InputStream inputStream = SMSUtils.class.getClassLoader().getResourceAsStream("aliyun.properties");
        Properties properties = new Properties();
        properties.load(inputStream);
        Object xxx = properties.get("xxx");*/


        com.aliyun.dysmsapi20170525.Client client = sendmsgutils.createClient("LTAI5tF5wswx96jQpKB4VkPy", "XF4jB2BrPBQHgP7z54jMLxuiM3FhBG");
        SendSmsRequest sendSmsRequest = new SendSmsRequest()
                .setPhoneNumbers(phone)
                .setSignName("杭州黑马传智健康")
                .setTemplateCode(templateCode)
                .setTemplateParam("{\"code\":\""+code+"\"}");
        // 复制代码运行请自行打印 API 的返回值
        SendSmsResponse smsResponse = client.sendSms(sendSmsRequest);
        if (smsResponse.getBody().getCode() == "OK") {
            return code;
        }
        System.out.println("smsResponse = " + smsResponse);
        return null;
    }


    public static void main(String[] args) throws Exception {
        sendMsg("15858250632", "SMS_184110818", "1234");
    }
}
